package masml2jade;

import jade.lang.acl.ACLMessage;

import java.util.Hashtable;

import masml2jade.agents.UsefulAgent;

public abstract class Organization extends UsefulAgent {

	private Hashtable<String, Axiom> axioms = new Hashtable<String, Axiom>();
	private Hashtable<String, Organization> subOrganizations = new Hashtable<String, Organization>();
	private Hashtable<String, ObjectRole> objectRoles = new Hashtable<String, ObjectRole>();
	// agentRoles are inherited by MAS_Agent class
	// enviroment is inherited by MAS_Agent class
	// goals are inherited by GoalAgent class
	// beliefs are inherited by ModelAgent class
	// plans are inherited by UsefulAgent class
	private Organization superOrganization ;
	
	// TODO: organizacoes em que a instancia de organizacao está exercendo os papéis
	// TODO: mensagens recebidas e enviadas
	/*
	 * Mensagens recebidas ja existe uma lista
	 * */

	protected Organization(Environment environment, AgentRole agentRole) {
		// The agentRole for Organization can be null initially, if it is 
		// a Super Organization, if not is mandatory
		super(environment, agentRole);
		initialize();
	}
	
	// Informs if this organization is a childOrganization
	public Organization getSuperOrganization() {
		return superOrganization;
	}
	public void setSuperOrganization(Organization superOrganization) {
		this.superOrganization = superOrganization;
	}
	
	// Axioms
	public Axiom getAxiom(String key) {
		return axioms.get(key);
	}
	public void addAxiom(String key, Axiom axiom) {
		axioms.put(key, axiom);
	}
	public Axiom removeAxiom(String key) {
		return axioms.remove(key);
	}
	
	// SubOrganizations
	public Organization getSubOrganization(String key) {
		return subOrganizations.get(key);
	}
	public void addSubOrganization(String key, Organization subOrganization) {
		subOrganizations.put(key, subOrganization);
	}
	public Organization removeSubOrganization(String key) {
		return subOrganizations.remove(key);
	}
	public void removeAllSubOrganizations() {
		subOrganizations.clear();
	}
	public Hashtable<String, Organization> getAllSubOrganizations() {
		return subOrganizations;
	}
	
	// objectRoles
	public ObjectRole getObjectRole(String key) {
		return objectRoles.get(key);
	}
	public void addObjectRole(String key, ObjectRole objectRole) {
		objectRoles.put(key, objectRole);
	}
	public ObjectRole removeObjectRole(String key) {
		return objectRoles.remove(key);
	}
	public void removeAllObjectRoles() {
		objectRoles.clear();
	}
	public Hashtable<String, ObjectRole> getAllObjectRoles() {
		return objectRoles;
	}
	
	protected final void usefulFunction() {
		// This method doesn't nothing, so it is final because 
		// UsefulAgent nesting
	}

	@Override
	protected abstract void initialize();
	
	public void sendM(ACLMessage msg) {
		// TODO Auto-generated method stub

	}
}
